<template>
  <div class="user-info">
    <el-dropdown>
      <span class="el-dropdown-link">
        <div class="block">
          <el-avatar :size="20" :src="circleUrl" />
        </div>
        <el-icon class="el-icon--right">
          <ArrowDown />
        </el-icon>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item :icon="Setting" @click="editLogin">
            退出登录
          </el-dropdown-item>
          <el-dropdown-item :icon="UserFilled" divided @click="toUserInfo">
            用户信息
          </el-dropdown-item>
          <el-dropdown-item :icon="Management">系统管理</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script>
import cache from "@/utils/cache.js";
import {
  ArrowDown,
  Setting,
  UserFilled,
  Management,
} from "@element-plus/icons-vue";
import { reactive, toRefs } from "vue";
import router from "@/router/index.js";
export default {
  components: { ArrowDown, Setting, UserFilled, Management },
  setup(props) {
    const data = reactive({
      circleUrl:
        "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
    });
    const editLogin = () => {
      cache.deleteCache("token");
      router.push("/login/logining");
    };
    const toUserInfo = () => {
      router.push("/main/product/goods");
    };
    return {
      ArrowDown,
      Setting,
      UserFilled,
      Management,
      ...toRefs(data),
      editLogin,
      toUserInfo,
    };
  },
};
</script>

<style lang="scss" scope>
.el-dropdown-link {
  display: flex;
  align-items: center;
}
.user-info {
  cursor: pointer;
  font-size: 14px;
  & .el-dropdown-menu__item {
    font-size: 14px;
  }
}
</style>
